// pages/index/consultyy/consultyy.js
const app = getApp();

Page({
  data: {
    url: '',
    show: false,
    levelList: [],
    levelName: '',
    consultTypeList: [],
    selectTypeList: [],
    typeName: '',
    content: '',
    level: '',
    typeIds: [],
  },

  showPopup1() {
    this.setData({ show1: true });
    let that = this;
    wx.request({
      url: that.data.url+'consultlevel2/findAll',
      method:  'GET',
      success(resp){
        let result = resp.data;
        console.log(result);
        that.setData({
          levelList: result,
        })
      }
    })
  },
  showPopup2() {
    this.setData({ show2: true });
    let that = this;
    wx.request({
      url: that.data.url+'specialty/findAll',
      method:  'GET',
      success(resp){
        let result = resp.data;
        console.log(result);
        that.setData({
          consultTypeList: result.data,
        });
      }
    })
  },
  showPopup3() {
    this.setData({ show3: true });
  },
  onClose1() {
    this.setData({ show1: false });
    console.log(666);
  },
  onClose2() {
    this.setData({ show2: false });
  },
  onClose3() {
    this.setData({ show3: false });
  },
  selectLevel(e){
    let level =  e.currentTarget.dataset.level;
    this.setData({
      show1: false,
      level: level,
      levelName: level.name,
    });
    console.log(this.data.levelName);
  },
  selectType(e){
    let type = e.currentTarget.dataset.type;

    let items = this.data.typeIds;
    items.push(type.id);
    let types = this.data.selectTypeList;
    types.push(type);
    this.setData({
      show2: false,
      typeName: type.name,
      typeIds: items,
      selectTypeList: types,
    });
    // console.log(this.data.levelName);
    console.log(this.data.typeIds);
  },
  onClose(e){
    let typeId = e.currentTarget.dataset.typeId;
    let typeIds = this.data.typeIds;
    let typeIdIndex = typeIds.indexOf(typeId);
    typeIds.splice(typeIdIndex,1);

    let type = e.currentTarget.dataset.type;
    let selectTypeList = this.data.selectTypeList;
    let typeIndex = selectTypeList.indexOf(type);
    selectTypeList.splice(typeIndex,1)
    this.setData({
      typeIds: typeIds,
      selectTypeList: selectTypeList
    })
  },
  goConsultSuccess(){
    let that = this;
    console.log(that.data.typeIds.join(','));
    wx.navigateTo({
      url: './consultsuccess/consultsuccess?level='+that.data.level.id+'&typeIds='+that.data.typeIds.join(','),
    });
    wx.setStorageSync('content', this.data.content);
  },
  goConsultInput(){
    wx.navigateTo({
      url: './consultinput/consultinput',
    })
  },
  goIndex(){
    wx.switchTab({
      url: '../index/index',
    });
    wx.removeStorageSync('content');
  },
  onLoad(options){
    this.setData({
      url: app.globalData.URL,
      content: options.content,
    })
    console.log(this.data.content);
  }
})